#!/usr/bin/env bash
# 安装必要的安装包
for packages in yum make cmake gcc gcc-c++ flex bison file libtool libtool-libs autoconf kernel-devel patch wget crontabs libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libzip-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap diffutils ca-certificates net-tools libc-client-devel psmisc libXpm-devel git-core c-ares-devel libicu-devel libxslt libxslt-devel xz expat-devel libaio-devel rpcgen libtirpc-devel perl python-devel cyrus-sasl-devel;
do yum -y install $packages; done
# 关闭selinux
if [ -s /etc/selinux/config ]; then
    sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
fi
# 开始更新GCC 5.3
wget -c http://ftp.gnu.org/gnu/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz
tar zxvf gcc-5.3.0.tar.gz
cd gcc-5.3.0
./contrib/download_prerequisites
cd ..
mkdir build_gcc_5.3.0
cd build_gcc_5.3.0/
../gcc-5.3.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

make -j23
make install
/usr/sbin/update-alternatives --install  /usr/bin/gcc gcc /usr/local/bin/x86_64-unknown-linux-gnu-gcc-4.8.1 40
gcc --version      #查看版本
/usr/sbin/update-alternatives --install /usr/bin/g++ g++ /usr/local/bin/g++ 40
g++ --version     #查看版本


# 开始编译安装cmake3
yum remove cmake
wget -c https://github.com/Kitware/CMake/releases/download/v3.15.0/cmake-3.15.0.tar.gz
tar zxvf cmake-3.15.0.tar.gz
cd cmake-3.15.0
./bootstrap --prefix=/usr/local/cmake
make && make install
ln -s /usr/local/cmake/bin/* /usr/bin


cur_dir=$(pwd)
# 开始安装MySQL 8
rm -f /etc/my.cnf
wget -c https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.16.tar.gz
tar zxvf mysql-boost-8.0.16.tar.gz
cd mysql-8.0.16
cur_dir=$(pwd)
/usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DFORCE_INSOURCE_BUILD=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=$cur_dir/boost


make -j `grep 'processor' /proc/cpuinfo | wc -l`
if [ $? -ne 0 ]; then
    make
fi
make install

